package org.ling.xuan.table;

import org.ling.xuan.entity.mo.SendRecord;

import javax.swing.table.AbstractTableModel;
import java.util.List;

public class SendRecordTableModel extends AbstractTableModel {
    private final List<SendRecord> sendRecordList;
    private final String[] columnNames = {"ID", "Target Email", "Title", "Modify IDs", "Require Bank", "Requirement ID", "Requirement Description", "Send Message"};

    public SendRecordTableModel(List<SendRecord> sendRecordList) {
        this.sendRecordList = sendRecordList;
    }

    @Override
    public int getRowCount() {
        return sendRecordList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        SendRecord sendRecord = sendRecordList.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return sendRecord.getId();
            case 1:
                return sendRecord.getTargetEmail();
            case 2:
                return sendRecord.getTitle();
            case 3:
                return sendRecord.getModifyIds();
            case 4:
                return sendRecord.getRequireBank();
            case 5:
                return sendRecord.getRequirementId();
            case 6:
                return sendRecord.getRequirementDes();
            case 7:
                return sendRecord.getSendMsg();
            default:
                return null;
        }
    }

    public void removeRow(int rowIndex) {
        sendRecordList.remove(rowIndex);
        fireTableRowsDeleted(rowIndex, rowIndex);
    }
}

